package com.sias.config;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2023/5/31 11:37
 */
public class WebApplicationInit implements WebApplicationInitializer {

  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(WebMVCConfig.class);
    webApplicationContext.register(SpringConfig.class);
    webApplicationContext.setServletContext(servletContext);

    ServletRegistration.Dynamic springmvc = servletContext.addServlet("springmvc", new DispatcherServlet(webApplicationContext));
    springmvc.addMapping("/");
    springmvc.setLoadOnStartup(1);
  }
}
